package com.atguigu.tingshu.listener;


import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.VipServiceConfig;
import io.xzxj.canal.core.annotation.CanalListener;
import io.xzxj.canal.core.listener.EntryListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Set;

@Slf4j
@CanalListener(destination = "tingshuTopic", schemaName = "tingshu_user", tableName = "vip_service_config")
public class VipConfigListener  implements EntryListener<VipServiceConfig> {


    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 监听vip信息套餐更新回调方法
     * @param before
     * @param after
     * @param fields
     */
    @Override
    public void update(VipServiceConfig before, VipServiceConfig after, Set<String> fields) {
        log.info("[cdc]监听到变更数据");
        String redisKey = "user:vipconfig:"+after.getId();
        redisTemplate.delete(redisKey);
    }
}
